home *** CD-ROM | disk | FTP | other *** search
/ Merciful 2 / Merciful - Disc 2.iso / software / e / experiment4codersdisk2.dms / experiment4codersdisk2.adf / play_freq.s < prev    next >
Text File  |  1992-09-02  |  8KB  |  258 lines

  1. *******************************************************************************
  2. * Multi-Frequency Dialer v1.02
  3. * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  4. * Dials "ASCII String" phone numbers. 
  5. *
  6. * Maybe the delay waiting should be changed to a more ~accurate~ method!
  7. * The short term botch method I`ve simple forbid() the OS and used lame raster
  8. * waiting... (I know that ciaa should be used!.. hehe)
  9. *
  10. * FastMem Bug fixed:
  11. * ~~~~~~~~~~~~~~~~~
  12. * The 4 byte sample is now first copied into chip-memory first then its played
  13. * before I forgot about this since I`ve only got chippy food in my A12oo...
  14. *
  15. * Dialer supports:
  16. * ~~~~~~~~~~~~~~~
  17. *        "0"-"9" and "b"-"c" are the tones!
  18. *        "." waits for a small delay
  19. *        "¹" enables DTMF Dial-frequency tones!
  20. *        "²" enables CITT Dial-frequency tones!
  21. *******************************************************************************
  22.  
  23. ;-------------- Definition Includes
  24.  
  25.         incdir    "includes:"
  26.         include    "exec/exec_lib.i"
  27.         include    "exec/memory.i"
  28.  
  29. ;CLI Params    =    a0=cli params ascii string ptr
  30. ;            d0=cli params length
  31.  
  32. DialEntry:    move.l    a0,-(sp)
  33.         move.l    4.w,a6
  34.         moveq    #4,d0            ;length of sample (4 bytes)
  35.         move.l    #MEMF_CHIP+MEMF_CLEAR,d1 ;we want chipmem, cleared
  36.         jsr    _LVOAllocMem(a6)    ;allocate it...4
  37.         move.l    d0,a2
  38.         beq.s    NoMem            ;did the alloc fail, if so exit
  39.         lea    SamplePtr(pc),a1
  40.         move.l    a2,(a1)            ;save sample memory ptr
  41.         lea    Sampledata(pc),a0
  42.         move.l    (a0),(a2)        ;put our 4 byte sample in chip!
  43.  
  44.         jsr    _LVOForbid(a6)        ;turn off multitasking()
  45.         move.l    (sp)+,a0
  46.  
  47.         bsr.s    DialNumber
  48.  
  49.         move.l    4.w,a6
  50.         jsr    _LVOPermit(a6)        ;turn on multitasking()
  51.  
  52.         move.l    SamplePtr(pc),a1    ;ptr to our RS.Variables base
  53.         move.l    a1,d0
  54.         beq.s    NoMem
  55.         moveq    #4,d0            ;no. of bytes to free
  56.         jsr    _LVOFreeMem(a6)        ;free the memory
  57. NoMem        moveq    #0,d0
  58.         rts
  59.  
  60. *******************************************************************************
  61. * DialNumber    - Dials an ASCII phone number 
  62. * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  63. * INPUTS:    a0=Pointer to ascii phone number
  64. *******************************************************************************
  65.  
  66. DialNumber:    lea    TablePtr(pc),a1
  67.         lea    FreqTable1(pc),a2
  68.         move.l    a2,(a1)            ;set default DTMF freqtable
  69. DialLoop:    move.b    (a0)+,d0        ;get ascii char, incr digit pos
  70.         bne.s    donumber        ;is this the last digit?, done!
  71.         rts
  72.  
  73. donumber:    cmp.b    #"-",d0            ;skip all '-' in string
  74.         beq.s    DialLoop
  75.         cmp.b    #" ",d0            ;skip all ' ' in string
  76.         beq.s    DialLoop
  77.         move.l    a0,-(sp)        ;preserve current digit pos
  78.         bsr.s    PlayDigit        ;play this digit
  79.         move.l    (sp)+,a0        ;restore current digit pos
  80.         bra.s    DialLoop        ;keep dialing digits until done
  81.  
  82. usa_digit:    move.b    (a0)+,d0
  83.         beq.s    usa_done
  84.         cmp.b    #"-",d0
  85.         beq.s    usa_digit
  86.         cmp.b    #" ",d0
  87.         beq.s    usa_digit
  88.         move.l    a0,-(sp)
  89.         bsr.s    PlayDigit
  90.         move.l    (sp)+,a0
  91.         bra.s    usa_digit
  92.  
  93. usa_done:    move.l    (sp)+,a0
  94. userdial:    move.b    (a0)+,d0        ;get ascii char, incr digit pos
  95.         beq.s    userdone        ;is this the last digit?, done!
  96.         cmp.b    #"-",d0
  97.         beq.s    userdial
  98.         cmp.b    #" ",d0
  99.         beq.s    userdial
  100.         move.l    a0,-(sp)        ;preserve current digit pos
  101.         bsr.s    PlayDigit        ;play this digit
  102.         move.l    (sp)+,a0        ;restore current digit pos
  103.         bra.s    userdial        ;keep dialing digits until done
  104. userdone:    move.b    #"²",d0
  105.         bsr.s    PlayDigit
  106.         move.b    #"c",d0
  107.         bra.w    PlayDigit
  108.  
  109. *******************************************************************************
  110. * PlayDigit    - Plays a frequency digit from freqtable - input value is ASCII
  111. * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  112. * INPUTS:    d0=(.B)    digit to play, (range "0"-"9" and "b"-"c")
  113. *******************************************************************************
  114.  
  115. PlayDigit:    lea    TablePtr(pc),a1
  116.         cmp.b    #"¹",d0            ;Are we setting DTMF Table?
  117.         beq.s    SetDTMF        
  118.         cmp.b    #"²",d0            ;Are we setting 890 FAST Table?
  119.         beq.s    SetFAST
  120.         
  121. SearchIt:    move.l    (a1),a0            ;dial table ptr
  122. search_freq    move.w    (a0)+,d1        ;get current freq
  123.         beq.s    notfound        ;this was the last one
  124.         cmp.b    d0,d1            ;is this the one we want?
  125.         beq.s    playit
  126.         addq.l    #6,a0            ;skip to next one
  127.         beq.s    notfound
  128.         bra.s    search_freq
  129.  
  130. SetDTMF:    lea    FreqTable1(pc),a0
  131.         move.l    a0,(a1)            ;save table freq ptr
  132.         rts
  133.     
  134. SetFAST        lea    FreqTable2(pc),a0
  135.         move.l    a0,(a1)            ;save table freq ptr
  136.         rts
  137.         
  138. PlayIt        move.w    d0,-(sp)        ;save digit value
  139.         move.w    (a0)+,d0        ;freq 1
  140.         move.w    (a0)+,d1        ;freq 2
  141.         move.w    (a0)+,-(sp)        ;save delay value to stack
  142.         bsr.s    FreqOn            ;turn on frequency
  143.         move.w    (sp)+,d2        ;restore delay value
  144.         bsr.b    _LVODelay        ;wait the delay()
  145.  
  146.         move.w    #15,$96(a6)        ;turn off sound dma
  147.         move.w    #$C000,$9A(a6)        ;turn off intena
  148.  
  149.         move.w    (sp)+,d0
  150.         cmp.b    #"!",d0            ;is this a multifreq 
  151.         bne.s    noter        ;if not exit and wait a while
  152.         move.b    #"#",d0            ;ELSE.. 
  153.         bra.s    PlayDigit
  154.  
  155. noter    move.l    #50-1,d2
  156.         bsr.b    _LVODelay        ;wait for 50 rasters
  157. notfound    rts
  158.  
  159.  
  160. _LVODelay:    ;d0=no. rasters to wait
  161.  
  162. waw1        cmp.b    #-1,$dff006        ;VERY DODGY WAITING METHOD!
  163.         bne.s    waw1            ;OOOER!
  164.         subq.l    #1,d2
  165.         bne.s    waw1
  166.         rts
  167.  
  168. *******************************************************************************
  169. * FreqOn    - Plays a Dual Frequency!
  170. * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  171. * INPUTS:    d0=(.W)    Frequency 1
  172. *        d1=(.W)    Frequency 2
  173. *        d2=(.W)    Volume
  174. *
  175. *******************************************************************************
  176.  
  177. FreqOn:        lea    $dff000,a6        ;custombase
  178.         tst.w    d0            ;is there a frequency 1?
  179.         beq.s    nofreq
  180.         tst.w    d1            ;is there a frequency 2?
  181.         beq.s    nofreq
  182.         
  183. ;-------------- Setup SampleDMA
  184.  
  185.         move.w    #$4000,$9A(a6)        ;intena
  186.         move.w    #15,$96(a6)        ;dmacon
  187.         move.w    #0,$9E(a6)        ;adkcon
  188.  
  189.         lea    $a0(a6),a5        ;$dff0a0=a5
  190.         move.l    sampleptr(pc),a0
  191.         move.w    #$40,d2            ;volume
  192.         moveq    #4/2,d3            ;length
  193.         moveq    #$00,d6            ;Channel 0
  194.         bsr.s    SetChannel
  195.         move.w    #$10,d6            ;Channel 1
  196.         bsr.s    SetChannel
  197.         exg    d0,d1            ;swap freq`s around
  198.         move.w    #$20,d6            ;Channel 2
  199.         bsr.s    SetChannel
  200.         move.w    #$30,d6            ;Channel 3
  201.         bsr.s    SetChannel
  202.  
  203. ;-------------- Set Channel DMA
  204.         move.w    #$8209,$96(a6)        ;turn on all 4 chanels
  205. NoFreq:        rts
  206.  
  207. SetChannel:    move.l    a0,(a5,d6.w)        ;sampledata ptr (AUDxPTH)
  208.         move.w    d1,$6(a5,d6.w)        ;sample period  (AUDxPER)
  209.         move.w    d2,$8(a5,d6.w)        ;sample volume  (AUDxVOL)
  210.         move.w    d3,$4(a5,d6.w)        ;sample length  (AUDxLEN)
  211.         rts
  212.  
  213. TablePtr    dc.l    0            ;ptr to table to use
  214.  
  215. delay        =    79
  216. ;            Digit,Freq1,Freq2,Len        "DTMF" Dial Frequecies
  217. ;            ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯        ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  218. FreqTable1:    dc    $0030,$03b4,$029c,delay        ;"0",freq1,freq2,delay
  219.         dc    $0031,$0501,$02e2,delay        ;"1",freq1,freq2,delay
  220.         dc    $0032,$0501,$029c,delay        ;"2",freq1,freq2,delay
  221.         dc    $0033,$0501,$025c,delay        ;"3",freq1,freq2,delay
  222.         dc    $0034,$0487,$02e2,delay        ;"4",freq1,freq2,delay
  223.         dc    $0035,$0487,$029c,delay        ;"5",freq1,freq2,delay
  224.         dc    $0036,$0487,$025c,delay        ;"6",freq1,freq2,delay
  225.         dc    $0037,$0417,$02e2,delay        ;"7",freq1,freq2,delay
  226.         dc    $0038,$0417,$029c,delay        ;"8",freq1,freq2,delay
  227.         dc    $0039,$0417,$025c,delay        ;"9",freq1,freq2,delay
  228.  
  229.         dc    $002e,$0000,$0000,500        ;".",delay
  230.         dc    0,0                ;end of table
  231.  
  232. delay2        =    100
  233. delaya        =    100
  234. delayb        =    100
  235. ;            Digit,Freq1,Freq2,Len        "890" Dial Frequecies
  236. ;            ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯        ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  237. FreqTable2:    dc    $0030,$02ae,$0253,delay2    ;"0",freq1,freq2,delay
  238.         dc    $0031,$04fb,$03e0,delay2    ;"1",freq1,freq2,delay
  239.         dc    $0032,$04fb,$032b,delay2    ;"2",freq1,freq2,delay
  240.         dc    $0033,$03e0,$032b,delay2    ;"3",freq1,freq2,delay
  241.         dc    $0034,$04fb,$02ae,delay2    ;"4",freq1,freq2,delay
  242.         dc    $0035,$03e0,$02ae,delay2    ;"5",freq1,freq2,delay
  243.         dc    $0036,$032b,$02ae,delay2    ;"6",freq1,freq2,delay
  244.         dc    $0037,$04fb,$0253,delay2    ;"7",freq1,freq2,delay
  245.         dc    $0038,$03e0,$0253,delay2    ;"8",freq1,freq2,delay
  246.         dc    $0039,$032b,$0253,delay2    ;"9",freq1,freq2,delay
  247.  
  248.         dc    $0062,$02ae,$020d,delaya    ;"b",freq1,freq2,delay
  249.         dc    $0063,$0253,$020d,delayb    ;"c",freq1,freq2,delay
  250.  
  251.         dc    $002e,$0000,$0000,500        ;".",delay
  252.         dc    0,0                ;end of table
  253.  
  254. SamplePtr    ds.l    1            ;ptr to the sample in chipmem!
  255.         even
  256. SampleData:    dc.w    127,128            ;sample data (2 words long)
  257.         even
  258.